package com.wiscofile.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.wiscofile.pojo.WiscoDataPlanproject;

/**
 * A data access object (DAO) providing persistence and search support for
 * WiscoDataPlanproject entities. Transaction control of the save(), update()
 * and delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.wiscofile.pojo.WiscoDataPlanproject
 * @author MyEclipse Persistence Tools
 */

public class WiscoDataPlanprojectDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory
			.getLog(WiscoDataPlanprojectDAO.class);
	
	public boolean save(WiscoDataPlanproject transientInstance) {
		try {
			Session session = getSession();
			Transaction tra = session.beginTransaction();
			session.clear();
			session.save(transientInstance);
			tra.commit();
			session.close();
			return true;
		} catch (RuntimeException re) {
			log.error("save failed", re);
			return false;
		}
	}
	
	public boolean update(WiscoDataPlanproject transientInstance) {
		try {
			Session session = getSession();
			Transaction tra = session.beginTransaction();
			session.clear();
			session.update(transientInstance);
			tra.commit();
			session.close();
			return true;
		} catch (RuntimeException re) {
			log.error("update failed", re);
			return false;
		}
	}

	public boolean delete(WiscoDataPlanproject persistentInstance) {
		try {
			Session session = getSession();
			Transaction tra = session.beginTransaction();
			session.delete(persistentInstance);
			tra.commit();
			session.close();
			return true;
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			return false;
		}
	}

	public WiscoDataPlanproject findById(java.lang.String id) {
		try {
			Session session = getSession();
			WiscoDataPlanproject instance = (WiscoDataPlanproject) session
			.get("com.wiscofile.pojo.WiscoDataPlanproject", id);
			session.close();
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public List findAll(int first,int pagesize) {
		try {
			Session session = getSession();
			String queryString = "from WiscoDataPlanproject";
			Query queryObject = session.createQuery(queryString);
			queryObject.setFirstResult(first);
			queryObject.setMaxResults(pagesize);
			List list = queryObject.list();
			session.close();
			return list;
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public int countAll() {
		try {
			Session session = getSession();
			String queryString = " select count(w) from WiscoDataPlanproject w";
			Query queryObject = session.createQuery(queryString);
			Long count = (Long) queryObject.list().get(0);
			session.close();
			return count.intValue();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public WiscoDataPlanproject merge(WiscoDataPlanproject detachedInstance) {
		log.debug("merging WiscoDataPlanproject instance");
		try {
			WiscoDataPlanproject result = (WiscoDataPlanproject) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(WiscoDataPlanproject instance) {
		log.debug("attaching dirty WiscoDataPlanproject instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(WiscoDataPlanproject instance) {
		log.debug("attaching clean WiscoDataPlanproject instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}